package com.funtl.spring.cloud.alibaba.consumer.service.fallback;

import com.funtl.spring.cloud.alibaba.consumer.service.EchoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import feign.hystrix.FallbackFactory;

/**
 * 用户服务降级处理
 *
 * @author ZhangXX
 *
 */
@Component
public class EchoServiceFallbackFactory implements FallbackFactory<EchoService> {
    private static final Logger log = LoggerFactory.getLogger(EchoServiceFallbackFactory.class);

    @Override
    public EchoService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new EchoService() {
            @Override
            public String echo(String string) {
                return "你的网络有问题" + throwable.getMessage();
            }

            @Override
            public String lb() {
                return "你的网络有问题" + throwable.getMessage();
            }
        };
    }
}
